package com.shengzai.mapreduce.wordcount;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

// Map阶段：切分每一行，通过空格分割，并遍历每一个单词，标记出现次数1。
public class MapWorldCount extends Mapper <LongWritable, Text,Text, IntWritable> {
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, IntWritable>.Context context) throws IOException, InterruptedException {
        String[] worlds = value.toString().split(" ");
        IntWritable flag = new IntWritable(1);
        for (String world : worlds) {
            context.write(new Text(world),flag);
        }
    }
}
